<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2019/10/23
 * Time: 9:55
 */

namespace search\controllers\marketDataAnalysis;

use business\elasticsearch\services\LandDetailsService;

class LandDetailsController extends BaseController
{
    /**
     * 市场数据-土地数据详情查询接口
     * @return \business\base\models\ResultModel
     */
    public function actionLandTake()
    {
        try {
            // 开发商ID
            $developerUid      = (int)$this->getParam('developer_uid');
            // 公司名称
            $companyName       = (int)$this->getParam('company_name');

            // 项目地区-大数据拓客
            $region            = $this->getParam('region');

            // 拿地开始时间-大数据拓客--拿地数据
            $takeLandStartDate = $this->getParam('start_date');
            // 拿地结束时间-大数据拓客--拿地数据
            $takeLandEndDate   = $this->getParam('end_date');

            // 土地用途-大数据拓客--拿地数据
            $landUsage         = $this->getParam('land_usage');

            $page              = (int)$this->getParam('page', 'get', '1');
            $pageSize          = (int)$this->getParam('pagesize', 'get', '10');

            if (empty($developerUid) && empty($companyName)) {
                return $this->error('', '开发商ID或公司名称不能为空');
            }

            if (empty($region)) {
                return $this->error('', '请先选择项目地区');
            }

            return $this->success((new LandDetailsService())->getLandTakeList(
                    $developerUid, $companyName, $region, $takeLandStartDate, $takeLandEndDate, $landUsage, $page, $pageSize));
        } catch (\Exception $ex){
            \Yii::error($ex->getMessage());
            return $this->error('', '获取失败，请稍后重试');
        }
    }

    /**
     * 市场数据-项目数据详情查询接口
     * @return \business\base\models\ResultModel
     */
    public function actionLandProject()
    {
        try {
            // 开发商ID
            $developerUid     = (int)$this->getParam('developer_uid');
            // 公司名称
            $companyName      = $this->getParam('company_name');

            // 项目地区-大数据拓客
            $region           = $this->getParam('region');

            // 开盘开始时间-大数据拓客--项目数据
            $openingStartTime = $this->getParam('opening_start_time');
            // 开盘结束时间-大数据拓客--项目数据
            $openingEndTime   = $this->getParam('opening_end_time');

            // 装修状况-大数据拓客--项目数据
            $decorate         = $this->getParam('decorate');

            $page             = (int)$this->getParam('page', 'get', '1');
            $pageSize         = (int)$this->getParam('pagesize', 'get', '10');

            if (empty($developerUid) && empty($companyName)) {
                return $this->error('', '开发商ID或公司名称不能为空');
            }

            if (empty($region)) {
                return $this->error('', '请先选择项目地区');
            }

            return $this->success((new LandDetailsService())->getLandProjectList(
                    $developerUid, $companyName, $region, $openingStartTime, $openingEndTime, $decorate, $page, $pageSize));
        } catch (\Exception $ex){
            \Yii::error($ex->getMessage());
            return $this->error('', '获取失败，请稍后重试');
        }
    }

    /**
     * 市场数据-开工数据详情查询接口
     * @return \business\base\models\ResultModel
     */
    public function actionLandConstruction()
    {
        try {
            // 开发商ID
            $developerUid      = (int)$this->getParam('developer_uid');
            // 公司名称
            $companyName       = (int)$this->getParam('company_name');

            // 项目地区-大数据拓客
            $region            = $this->getParam('region');

            // 开始时间-大数据拓客--开工数据
            $contractStartTime = $this->getParam('contract_start_time');
            // 结束时间-大数据拓客--开工数据
            $contractEndTime   = $this->getParam('contract_end_time');

            $page              = (int)$this->getParam('page', 'get', '1');
            $pageSize          = (int)$this->getParam('pagesize', 'get', '10');

            if (empty($developerUid) && empty($companyName)) {
                return $this->error('', '开发商ID或公司名称不能为空');
            }

            if (empty($region)) {
                return $this->error('', '请先选择项目地区');
            }

            return $this->success((new LandDetailsService())->getLandConstructionList
                ($developerUid, $companyName, $region, $contractStartTime, $contractEndTime, $page, $pageSize));
        } catch (\Exception $ex){
            \Yii::error($ex->getMessage());
            return $this->error('', '获取失败，请稍后重试');
        }
    }
}
